package com.chen.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.springboot.entity.Dict;
import com.chen.springboot.entity.Poster;
import com.chen.springboot.mapper.PosterMapper;
import com.chen.springboot.service.PosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenchao
 * @date 2022/6/17 13:42
 */
@Service
@Transactional
public class PosterServiceImpl extends ServiceImpl<PosterMapper, Poster> implements PosterService {

    @Resource
    private PosterMapper posterMapper;

    public IPage<Poster> selectPage(Integer pageNum, Integer pageSize,String comment) {
//        创建Page1对象
        IPage<Poster> page = new Page<Poster>(pageSize, pageNum);
//QueryWrapper如果name不为空进行模糊查询
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("sort");
        if(!"".equals(comment)){
            queryWrapper.like("comment",comment);
        }


        Page<Poster> selectPage = posterMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
        return selectPage;

    }


    @Override
    public List<Poster> selectIsEnablePoster() {
        return posterMapper.selectIsEnablePoster();
    }
}
